<?php
require_once('kelas/record.php');
require_once('kelas/kategori.php');

require_once('kelas/produk.php');
require_once('kelas/pemesanan.php');
require_once('kelas/fungsi.php');
require_once('kelas/amankanParam.php');
$dtGet = $objParamAman->getMethod();
$dtPost = $objParamAman->postMethod();

?>
<link rel="stylesheet" type="text/css" href="<?php echo BASEURL;?>css/isi.css" />
<style type="text/css">
    font.font-info{
        font-weight: bolder;color:red;
    }
</style>    
    <?php
if (isset($dtGet['ord'])) {
    $dtPesan = $objPemesanan->getDataPesan($dtGet['ord']);
    if ($dtPesan['header']['success'] == false) {
        echo $objFungsi->alert($dtPesan['header']['error_msg']) . $objFungsi->redirect(BASEURL);
        exit;
    }
    $totalUInfo = 0;

    $dtHeader = $dtPesan['header'];
    $dtDetail = $dtPesan['detail'];
    foreach ($dtDetail as $k => $value) {
        $hrg = $value['diskon'] > 0 ? ($value['harga_awal'] - ($value['harga_awal'] * ($value['diskon'] / 100))) : $value['harga_awal'];
        $totalUInfo +=$hrg * $value['jumlah_buy'];
    }
    echo $objFungsi->buatJudul('Terima Kasih',113);
	?>
    
    <p>Data Pesanan Anda Telah Kami Terima</p>
    <p>Nomor Pemesanan</p>
    <h3><?php echo $dtGet['ord']; ?></h3>

    <p>Silahkan transfer total belanja sejumlah <font class='font-info'> <?php echo "Rp." . number_format(($totalUInfo + $dtHeader['biaya_ongkir']), 0, '.', ','); ?></font>
        ke nomor rekening <?php echo "<font class='font-info'>".$dtHeader['norek']."</font> (<font class='font-info'>".$dtHeader['bank']."</font> cabang 
            <font class='font-info'>".$dtHeader['cabang']."</font> atas nama <font class='font-info'>".$dtHeader['atasnama']."</font>)"?>
    </p>
    <p>Maksimal penundaan pembayaran 3 Hari dari tanggal <?php echo date('d F Y',strtotime($dtHeader['tanggal'])); ?>. Lebih dari itu maka pemesanan dianggap dibatalkan.  </p>
    <?php echo $objFungsi->buatJudul('',112) ?>
    <br/>
    <?php echo $objFungsi->buatJudul('Detail Pesanan',112); ?>
    <div class="frame_table_order">
<table width="100%" cellpadding="5" cellspacing="0" border="1" style="border-collapse:collapse">

    <thead>
        <tr align="center" valign="middle" bgcolor="#CCCCCC">            <th>No</th>
                <th>Gambar</th>
                <th>Nama</th>
                <th>Harga</th>
                <th>Qty</th>
                <th>Subtotal</th>
            </tr>   
        </thead>
        <tbody>
            <?php
            $total = 0;

            if (count($dtDetail) < 1) {
                ?>
                <tr>
                    <td colspan="7">(belum ada item)</td>

                </tr>
                <?php
            } else {
                $no = 1;

                foreach ($dtDetail as $k => $value) {
                    $hrg = $value['diskon'] > 0 ? ($value['harga_awal'] - ($value['harga_awal'] * ($value['diskon'] / 100))) : $value['harga_awal'];
                    ?>
                    <tr> 
                        <td><?php echo $no++; ?></td>
                        <td><img style="width:50px;height:50px" src="<?php echo BASEURL . 'produk/' . $value['gambar']; ?>"/></td>
                        <td><?php echo $value['nama']; ?></td>
                        <td style="text-align: right"><?php echo ($value['diskon'] > 0) ? "<span style='text-decoration:line-through;color:red;font-size:small'>" . number_format($value['harga_awal'], 0, '.', ',') . "</span><br/>" : "";
            echo number_format($hrg, 0, '.', ',') ?></td>
                        <td>
                            <input disabled="disabled" value="<?php echo $value['jumlah_buy']; ?>" class="text_box_50" name="buy[<?php echo (string) $k; ?>]" />
                            <input value="<?php echo $value['id']; ?>" type="hidden" class="text_box_50" name="id[<?php echo (string) $k; ?>]" />
                        </td>
                        <td style="text-align: right"><?php $total +=$hrg * $value['jumlah_buy'];
            echo number_format($hrg * $value['jumlah_buy'], 0, '.', ','); ?></td>

                    </tr>
                    <?php
                }
            }
            ?>

        </tbody>
        <tfoot>
            <tr>
                <th colspan="6" style="text-align: right">Total: <input 
                        style="text-align:right" 
                        type="text" 
                        class="option" 
                        disabled="disabled" 
                        value="<?php echo "Rp. " . number_format($total, 0, '.', ','); ?>" />
                </th>
            </tr>

        </tfoot>
    </table>
</div>
    <div style="float:left;width:60%">
        <br/>
        <?php echo $objFungsi->buatJudul('Alamat Pengiriman',60) ?>
        <table class="tabel-data">
            <tr> <td>Nama Pemesan</td> <td><?php echo $dtHeader['nama'] ?></td> </tr>
            <tr> <td>Nama Penerima</td> <td><?php echo $dtHeader['nama_penerima'] ?></td> </tr>
            <tr> <td>E-mail Penerima</td> <td><?php echo $dtHeader['email_penerima']; ?></td> </tr>
            <tr> <td>Telepon Penerima</td> <td><?php echo $dtHeader['telepon_penerima']; ?></td> </tr>
            <tr> <td>Pesan Tambahan</td> <td><?php echo $dtHeader['pesan_tambahan']; ?></td> </tr>
            <tr> <td>Kota</td> <td> <?php echo $dtHeader['kota_penerima'] ?></td></tr>
            <tr> <td>Alamat Penerima</td> <td> <?php echo $dtHeader['alamat_penerima'] ?></td></tr>
        </table>
    </div>
    <div style="float:right;width:40%">
        <br >
        <?php echo $objFungsi->buatJudul('Total Pembayaran',43); ?>
        <table class="tabel-data">
            <tr><td>Total Belanja</td><td><?php echo "Rp. " . number_format($total, 0, '.', ','); ?></td></tr>
            <tr><td>Biaya Kirim Ke <?php echo $dtHeader['kota_penerima']; ?></td><td><?php echo "Rp. " . number_format($dtHeader['biaya_ongkir'], 0, '.', ','); ?></td></tr>
            <tr><td>Total Transfer</td><td><?php echo "Rp. " . number_format(($total + $dtHeader['biaya_ongkir']), 0, '.', ','); ?></td></tr>
                    </table>
    </div>
    <?php
    //$objFungsi->var_dump($dtHeader);
} else {
    echo $objFungsi->redirect(BASEURL);
}
?>